﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufArrangementAreaContent.h"

namespace gnuf {

    class QtWindow;
    class QtDesktop;
    class DesktopArrangementArea;
    class ArrangementAreaEvent;
    class Desktop final : public ArrangementAreaContent
    {
        DEFINE_CAST_DERIVED(Desktop, ArrangementAreaContent)
    public:
        explicit Desktop(const std::wstring & key);
        ~Desktop();

        // Initialize/uninitialize the desktop.
        void initialize(const std::wstring & fileName, bool fromDefaultDirectory = false);
        bool initialized() const { return (nullptr != m_desktop.get()); }
        void uninitialize();

        QtWindow * qtWindow();

        void recordJournal(const std::wstring & arrangementAreaContentKey,
            const ArrangementAreaContent::JournalParameters &);

    protected:
        // Inherits from ArrangementAreaContent...
        virtual QWidget * qtWidget() override;
        virtual void onPostVisibilityChanged() override;
        virtual void onPostConnectedWithArrangementArea() override;
        virtual void onPreDisconnectedFromArrangementArea() override;
        virtual void onPostGeometryChanged() override;
        virtual void onEvent(ArrangementAreaEvent*) override;

    private:
        gcmp::OwnerPtr< DesktopArrangementArea > m_desktop;
        QtDesktop * m_qtDesktop;
    };

}
